<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
      <span class="text">{{title.length > 8 ? title.substring(0,8) + "..." : title}}</span>
        <div class="e-icon"  v-show="show">
          <i class="el-icon-edit" style="margin-right:22px;" @click.stop="gotoNoteMark"></i>
          <i class="el-icon-delete-solid" @click.stop="deleteNote"></i>
        </div>
      </div>
      <div v-html="this.info">
      </div>
    </el-card>
  </div>
</template>

<script>
import axios from "axios";
import qs from 'qs'
import "github-markdown-css"
import MarkdownIt from "markdown-it";
export default {
  name: "note_card",
  data(){
    return{
      show:false,
      icon_color:'#409EFF',
      noteId:this.id,
      info:this.content
    }
  },
  props:{
    id:Number,
    title:String,
    index:Number,
    isShow:Boolean,
    content:String
  },
  watch:{
    isShow(){
      this.show = this.isShow;
    }
  },
  created() {
    var MarkdownIt = require("markdown-it")
    var md = new MarkdownIt()
    this.info =  md.render(this.info)
  },
  methods:{

    deleteNote(){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.post('http://localhost:8089/note/delete',qs.stringify({noteId:this.noteId})).then(res => {
          this.$emit("deleteNote")
        })
        this.$message({
          type: 'success',
          message: '删除成功!'
        });

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    gotoNoteMark(){
      const _this = this;
      this.$router.push({
        name:"BlogEdit",
        query:{
          noteId:_this.id
        }
      })
    },
  }
}
</script>

<style scoped>

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 90%;
  height: 200px;
  margin-top: 6%;
  border-radius: 10px

}
.e-icon{
   float: right;
}
.el-icon-edit:hover,.el-icon-delete-solid:hover {
  color: #409EFF;
}
.text:hover{
  color: #409EFF;
}
.text{
   font-size: 20px;
}
</style>